﻿using System;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

namespace libEngineAI
{
	public static class Util
	{
		// Deep clone
		public static T DeepClone<T>(this T a)
		{
			using (MemoryStream stream = new MemoryStream())
			{
				BinaryFormatter formatter = new BinaryFormatter();
				formatter.Serialize(stream, a);
				stream.Position = 0;
				return (T) formatter.Deserialize(stream);
			}
		}
	}
}

